package com.josework.springhelloworld.entity;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.PropertySource;

import java.text.DecimalFormat;
import java.util.*;
import java.util.Comparator;
import java.util.stream.Collectors;

public class OuterClass implements Runnable{

    private String Outername;

    private int age;

    @Override
    public void run() {


    }

    //成员方法
    private void display(){
        System.out.println("这是外部类方法！");
        System.out.println(Outername);
    }

    private static String replaceCommasWithParentheses(String source){

        if (!StringUtils.isEmpty(source)){
            StringBuilder sb = new StringBuilder(source);
            int start = source.indexOf(",");
            int end = source.lastIndexOf(",");
            if (start == end){
                return sb.toString();
            }else{
                sb.replace(start,++start,"(");
                sb.replace(end,++end,")(");
                sb.append(")");
//                sb.insert(start,"\\");

            }
            return sb.toString();
        }
        return source;
    }

    class InnerClass extends Throwable implements Runnable{

        //成员变量
        private String InnerNme;

        public InnerClass(){
            InnerNme = "Joseph";
            Outername = "outer";
            age = 28;
        }

        //成员方法
        public void display(){
            System.out.println("这是内部类方法！");
            System.out.println(InnerNme);
            System.out.println(Outername);
        }

        @Override
        public void run() {
            //内部类拥有外部类的访问权
            System.out.println(OuterClass.this.Outername);
            System.out.println(OuterClass.this.age);
        }
    }

    public static void main(String[] args) {

        OuterClass outerClass = new OuterClass();
//        int i = Integer.parseInt("");
//        Long.valueOf("");

//        Collection
        InnerClass innerClass = outerClass.new InnerClass();

        Calendar instance = Calendar.getInstance();

        Date time = instance.getTime();

        innerClass.display();

        outerClass.display();

        double  d = 10/3.0;

        System.out.println(d);

        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String format = decimalFormat.format(d);
        System.out.println(format);

        String s = "CN_NBMaijietike_wap,101412,CN";
        String s1 = replaceCommasWithParentheses(s);

        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        Long n = list.stream().collect(Collectors.counting());
        list.add("e");
        list.add("d");
        List<String> res = list.stream()
                .sorted(Comparator.reverseOrder())
                .limit(n)
                .collect(Collectors.toList());


    }


}
